package vy.org.app.page.lookup.religion;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vy.dal.dao.lookup.VyLookupReligionDAO;
import org.vy.dal.dao.lookup.VyLookupReligionDO;

import vy.org.app.common.AppConstants;
import vy.org.app.common.BaseAction;
import vy.org.app.common.ModeEnum;
import vy.org.app.common.ModuleEnum;

/**
 * @author Ravi Shankar
 * 
 */
public class MntnReligionAction extends BaseAction {

	@Override
	public ActionForward executeAction(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {
		MntnReligionForm form = (MntnReligionForm) actionForm;
		VyLookupReligionDO dto = new VyLookupReligionDO();

		if (form != null && form.getMode() != null) {
			if (ModeEnum.ADD.getName().equals(form.getMode())) {

				dto = MntnReligionAssembler.getAssembler().getLookupReligionDO(
						form);
				try {
					VyLookupReligionDAO.insert(dto);
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else {
				if (ModeEnum.SEARCH.getName().equals(form.getMode())) {

					dto = MntnReligionAssembler.getAssembler()
							.getLookupReligionDO(form);
					try {
						request.setAttribute(AppConstants.RESULT,
								VyLookupReligionDAO.findByParam(dto));
					} catch (Exception e) {
						e.printStackTrace();
					}

				}
			}
		}
		return mapping.findForward("success");
	}

	@Override
	protected ModuleEnum getModuleId() {

		return ModuleEnum.MAINTAIN_RELIGION;
	}

}
